﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;

namespace Sinacor.OMM.FileTail
{
    static class Program
    {

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] filesArgument)
        {
            string mySelfExecutableFile;
            string myArgumentFile = string.Empty;

            if (filesArgument != null)
            {
                mySelfExecutableFile = Application.ExecutablePath;

                if (filesArgument.Length > 0)
                {
                    if (filesArgument.Length > 1)
                    {
                        string argsToNextProcess = string.Empty;

                        for (int idx = 1; idx < filesArgument.Length; idx++)
                        {
                            argsToNextProcess += filesArgument[idx].Replace(" ", "*") + " ";
                        }

                        Thread.Sleep(500);
                        Process.Start(mySelfExecutableFile, argsToNextProcess.Substring(0, argsToNextProcess.Length-1));
                    }
                    myArgumentFile = filesArgument[0].Replace("*", " ");
                }
            }

            

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TraceTail(myArgumentFile));
        }

    }
}
